package com.base.publish;

import com.base.util.ConnectionUtil;
import com.rabbitmq.client.*;

import java.io.IOException;

public class SimpleReceive {
    //队列名称
    private static final String QUEUE_NAME = "test_simple_queue";

    public static void main(String[] args) {
        try {
            //获取连接
            Connection connection = ConnectionUtil.getConnection();
            //从连接中获取一个通道
            Channel channel = connection.createChannel();
            //声明队列
            channel.queueDeclare(QUEUE_NAME, false, false, false, null);

            //监听队列
            channel.basicConsume(QUEUE_NAME, true, new MyConsumer(channel));
        } catch (IOException | ShutdownSignalException | ConsumerCancelledException e) {
            e.printStackTrace();
        }
    }
}